place additional text at specific location in template using Word export

I am using the Word export dxl file and a template. I am trying to place a line of text about the baseline used during export at the specific location: after the table of contents but before section 1 (the first row in the main column exported by DOORS). Currently I am able to write the line of text to the top of the document but not where I want it. Does anyone have any advice on how to modify the Word export dxl code to do this? I am not sure if I should add a bookmark or modify the template. Thanks for your help!
SystemAdmin - Thu Jan 24 10:04:44 EST 2013

Re: place additional text at specific location in template using Word export
Mathias Mamsch - Thu Jan 24 17:31:42 EST 2013

Well WEXP does it this way, and I would consider that a good choice: In the Word Template you place some special fields, in the case of WEXP something like:

<<BaselineInfo>> or <<MyCustomAttribute>>

WEXP will then after the export, use the Word Search to look for all fields in the Template that are encapsulated in <<...>> and then check the content if
  • it is a valid attribute value, replace the tag by the value
  • if it is a special term like "BaselineInfo" then replace the tag by the exported baseline
  • etc.

I think you get the idea. This will make you very flexible in inserting the text in the template in a position that you like, using a formatting that you like. Maybe that helps,

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: place additional text at specific location in template using Word export
SystemAdmin - Tue Jan 29 12:02:42 EST 2013

Mathias Mamsch - Thu Jan 24 17:31:42 EST 2013
Well WEXP does it this way, and I would consider that a good choice: In the Word Template you place some special fields, in the case of WEXP something like:

<<BaselineInfo>> or <<MyCustomAttribute>>

WEXP will then after the export, use the Word Search to look for all fields in the Template that are encapsulated in <<...>> and then check the content if

  • it is a valid attribute value, replace the tag by the value
  • if it is a special term like "BaselineInfo" then replace the tag by the exported baseline
  • etc.

I think you get the idea. This will make you very flexible in inserting the text in the template in a position that you like, using a formatting that you like. Maybe that helps,

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Thank you Mathias, that greatly clarifies my understanding of how WEXP works!

What if the special tag is in the WEXP file and not in the module. For example: This is my snippet of code added to the WEXP file:

//---------------------Definitions---------------------
string results = "",tempFilter = "", myPath = "", myName = ""
Filter myFilt = current

//---------------------get & display module information---------------------

//display the path of the Module
myPath = path(Module m)
clear objArgBlock
put(objArgBlock, "Path of Module: " myPath "\n")
oleMethod(objSel, "TypeText", objArgBlock)

//display the name of the Module

myName = name(Module m)
clear objArgBlock
put(objArgBlock, "Name of Module: " myName "\n")
oleMethod(objSel, "TypeText", objArgBlock)

//get the baseline applied at export
//determine if a baseline exists or not. If it does not exist, the module is the current version
Baseline b = getMostRecentBaseline(m)
if b == null then {
clear objArgBlock
put(objArgBlock, "The Module is the current version at the time of export. \n")
checkRes(oleMethod(objSel, "TypeText", objArgBlock))
}
else {
clear objArgBlock
put(objArgBlock, "Module version at the time of export: " version(m) "\n")
checkRes(oleMethod(objSel, "TypeText", objArgBlock))
}

//display the filter or if no filter was applied during export
bool answer = filtering(m)
if answer == false then {
clear objArgBlock
put(objArgBlock, "The filter was not applied at export \n")
oleMethod(objSel, "TypeText", objArgBlock)
}
else {
if (! null myFilt) {
tempFilter = stringOf(m,myFilt)
results = results "DOORS filter applied at export: " tempFilter
tempFilter = ""
}
else {
results = results "No filter\n\n"
}
}
//display the description of the filter being applied
clear objArgBlock
put(objArgBlock, results "\n")
oleMethod(objSel, "TypeText", objArgBlock)
This is what I used to write the information I wanted to the word document before and it worked well. Now that I must reposition my text to a different location in the word document using <<>> like you suggested, what should I enter in the <<>> of the template? I tried my variable names, the actual function, etc. Is this even possible to take information from the WEXP script and place it in the word document using <<>> or should I be taking a different approach?

Thank you

Re: place additional text at specific location in template using Word export
Mathias Mamsch - Tue Jan 29 14:34:06 EST 2013

SystemAdmin - Tue Jan 29 12:02:42 EST 2013
Thank you Mathias, that greatly clarifies my understanding of how WEXP works!

What if the special tag is in the WEXP file and not in the module. For example: This is my snippet of code added to the WEXP file:

//---------------------Definitions---------------------
string results = "",tempFilter = "", myPath = "", myName = ""
Filter myFilt = current

//---------------------get & display module information---------------------

//display the path of the Module
myPath = path(Module m)
clear objArgBlock
put(objArgBlock, "Path of Module: " myPath "\n")
oleMethod(objSel, "TypeText", objArgBlock)

//display the name of the Module

myName = name(Module m)
clear objArgBlock
put(objArgBlock, "Name of Module: " myName "\n")
oleMethod(objSel, "TypeText", objArgBlock)

//get the baseline applied at export
//determine if a baseline exists or not. If it does not exist, the module is the current version
Baseline b = getMostRecentBaseline(m)
if b == null then {
clear objArgBlock
put(objArgBlock, "The Module is the current version at the time of export. \n")
checkRes(oleMethod(objSel, "TypeText", objArgBlock))
}
else {
clear objArgBlock
put(objArgBlock, "Module version at the time of export: " version(m) "\n")
checkRes(oleMethod(objSel, "TypeText", objArgBlock))
}

//display the filter or if no filter was applied during export
bool answer = filtering(m)
if answer == false then {
clear objArgBlock
put(objArgBlock, "The filter was not applied at export \n")
oleMethod(objSel, "TypeText", objArgBlock)
}
else {
if (! null myFilt) {
tempFilter = stringOf(m,myFilt)
results = results "DOORS filter applied at export: " tempFilter
tempFilter = ""
}
else {
results = results "No filter\n\n"
}
}
//display the description of the filter being applied
clear objArgBlock
put(objArgBlock, results "\n")
oleMethod(objSel, "TypeText", objArgBlock)
This is what I used to write the information I wanted to the word document before and it worked well. Now that I must reposition my text to a different location in the word document using <<>> like you suggested, what should I enter in the <<>> of the template? I tried my variable names, the actual function, etc. Is this even possible to take information from the WEXP script and place it in the word document using <<>> or should I be taking a different approach?

Thank you

Well this page here, shows how to do a search replace in Word:

http://msdn.microsoft.com/en-us/library/office/aa211953%28v=office.11%29.aspx

This is what you need to do in DXL. You need to query your complete document (including headers, footers, etc.) for any text like "<<Your special Tag>>". A search expression you could use, would be for example:
 

[<]{2;2}[!>]@[>]{2;2}

 


which will find stuff like <<mod.Attribute Name>>, <<Baseline Info>>, ...

Now in your DXL when you iterate over your search results:

 

 

 

bool moreFound = true
 
while (true) {
    oleCheck oleMethod(myFindObject, "Execute", findArguments) // Execute the search 
 
    oleCheck oleGet(myFindObject, "Found", moreFound)
 
    if (!moreFound) break; 
 
    // get the text from the range 
    oleGet (myRange, "Text", selectionText)
 
    if (selectionText == "Baseline Info") {
        // ... export baseline information to the range...
    }
 
    if (selectionText[0:3] == "mod.") {
       // ... read attribute and export its value to the range ...
    }
}



This is just to illustrate on how you could go about this. Maybe it helps, regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: place additional text at specific location in template using Word export
llandale - Tue Jan 29 16:00:55 EST 2013

Mathias Mamsch - Tue Jan 29 14:34:06 EST 2013

Well this page here, shows how to do a search replace in Word:

http://msdn.microsoft.com/en-us/library/office/aa211953%28v=office.11%29.aspx

This is what you need to do in DXL. You need to query your complete document (including headers, footers, etc.) for any text like "<<Your special Tag>>". A search expression you could use, would be for example:
 

[<]{2;2}[!>]@[>]{2;2}

 


which will find stuff like <<mod.Attribute Name>>, <<Baseline Info>>, ...

Now in your DXL when you iterate over your search results:

 

 

 

bool moreFound = true
 
while (true) {
    oleCheck oleMethod(myFindObject, "Execute", findArguments) // Execute the search 
 
    oleCheck oleGet(myFindObject, "Found", moreFound)
 
    if (!moreFound) break; 
 
    // get the text from the range 
    oleGet (myRange, "Text", selectionText)
 
    if (selectionText == "Baseline Info") {
        // ... export baseline information to the range...
    }
 
    if (selectionText[0:3] == "mod.") {
       // ... read attribute and export its value to the range ...
    }
}



This is just to illustrate on how you could go about this. Maybe it helps, regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

I don't recall the details, but years ago my partner had an export Word Template *.dot file used during the export. It had some kind of "variable" defined and the template had commands to "Display Variable X here" commands. His custom Word export DXL script had the ability to set these variable's names; and thus this information would appear in the export.

For example he put variable "Document Name" in the 1st page and in the Footer. His DXL did this:
  • SetMsWordVariable("Document Name", probeAttr_(mod, "ExportDocName"))

-Louie

Re: place additional text at specific location in template using Word export
adevicq - Wed Jan 30 06:54:57 EST 2013

llandale - Tue Jan 29 16:00:55 EST 2013
I don't recall the details, but years ago my partner had an export Word Template *.dot file used during the export. It had some kind of "variable" defined and the template had commands to "Display Variable X here" commands. His custom Word export DXL script had the ability to set these variable's names; and thus this information would appear in the export.

For example he put variable "Document Name" in the 1st page and in the Footer. His DXL did this:

  • SetMsWordVariable("Document Name", probeAttr_(mod, "ExportDocName"))

-Louie

Hi,

I wrote a function that locates a tag in the document and selects it. The idea is that once the tag is selected, you can output whatever you want to word to replace the selected string.

//----------------------------------------------------------------
// Searches for a string in the doc from the top 
//----------------------------------------------------------------
void wordFindString(string arg) {
    OleAutoObj objSelection = null
        OleAutoObj objFind = null
 
        if (arg == "") {
                endKey()
                return 
        }
        oleGet (objWord, "Selection", objSelection)
        if (objSelection == null) {
                print "selection = null\n"
        return 
         }
        oleGet(objSelection, "Find", objFind)
        if (objFind == null) {
                print "find = null\n"
                 return 
        }
 
        olePut(objFind, "Text", arg)
        olePut(objFind, "Wrap", wdFindContinue)
        oleMethod(objFind, cMethodExecute)
}


Note that I do not test the return code of the "FindContinue" operation in word...

to be used the following way:

 

// Put a tag such as %%the tag to replace%% in you dot somewhere
wordFindString("%%the tag to replace%%")
// write the string you need to write here with the function you use to output a string to MSWord



Regards,
Alain



 

Re: place additional text at specific location in template using Word export
llandale - Wed Jan 30 09:54:50 EST 2013

adevicq - Wed Jan 30 06:54:57 EST 2013

Hi,

I wrote a function that locates a tag in the document and selects it. The idea is that once the tag is selected, you can output whatever you want to word to replace the selected string.

//----------------------------------------------------------------
// Searches for a string in the doc from the top 
//----------------------------------------------------------------
void wordFindString(string arg) {
    OleAutoObj objSelection = null
        OleAutoObj objFind = null
 
        if (arg == "") {
                endKey()
                return 
        }
        oleGet (objWord, "Selection", objSelection)
        if (objSelection == null) {
                print "selection = null\n"
        return 
         }
        oleGet(objSelection, "Find", objFind)
        if (objFind == null) {
                print "find = null\n"
                 return 
        }
 
        olePut(objFind, "Text", arg)
        olePut(objFind, "Wrap", wdFindContinue)
        oleMethod(objFind, cMethodExecute)
}


Note that I do not test the return code of the "FindContinue" operation in word...

to be used the following way:

 

// Put a tag such as %%the tag to replace%% in you dot somewhere
wordFindString("%%the tag to replace%%")
// write the string you need to write here with the function you use to output a string to MSWord



Regards,
Alain



 

Do I understand correctly? A typical export continues to move the insertion point (the cursor) after the last pasted text and therefore remains at the bottom of the document. Your code effectively moves the insertion point and selects text such that the next word paste erases the selected text?

-Louie

Seems to me this function should return a boolean success flag.

Re: place additional text at specific location in template using Word export
adevicq - Thu Jan 31 04:49:22 EST 2013

llandale - Wed Jan 30 09:54:50 EST 2013
Do I understand correctly? A typical export continues to move the insertion point (the cursor) after the last pasted text and therefore remains at the bottom of the document. Your code effectively moves the insertion point and selects text such that the next word paste erases the selected text?

-Louie

Seems to me this function should return a boolean success flag.

Yes. It selects the text and when you output some text to MS Word it erases the selected text (in fact it pastes the new text and therefore replaces the selection).
You're right about the boolean return code. I have updated the method:

//----------------------------------------------------------------
// Searches for a string in the doc from the top 
//----------------------------------------------------------------
bool wordFindString(string arg) {
    OleAutoObj objSelection = null
        OleAutoObj objFind = null
        bool bResult = false
 
        if (arg == "") {
                endKey()
                return false
        }
        oleGet (objWord, "Selection", objSelection)
        if (objSelection == null) {
                print "selection = null\n"
                return false
        }
        oleGet(objSelection, "Find", objFind)
        if (objFind == null) {
                print "find = null\n"
                return false
        }
 
        olePut(objFind, "Text", arg)
        olePut(objFind, "Wrap", wdFindContinue)
        oleMethod(objFind, cMethodExecute, null, bResult)
        if (bResult == false)
            print "The tag " arg " has not been found\n" 
    return bResult 
}


Alain

Re: place additional text at specific location in template using Word export
SystemAdmin - Thu Jan 31 09:22:35 EST 2013

adevicq - Thu Jan 31 04:49:22 EST 2013

Yes. It selects the text and when you output some text to MS Word it erases the selected text (in fact it pastes the new text and therefore replaces the selection).
You're right about the boolean return code. I have updated the method:

//----------------------------------------------------------------
// Searches for a string in the doc from the top 
//----------------------------------------------------------------
bool wordFindString(string arg) {
    OleAutoObj objSelection = null
        OleAutoObj objFind = null
        bool bResult = false
 
        if (arg == "") {
                endKey()
                return false
        }
        oleGet (objWord, "Selection", objSelection)
        if (objSelection == null) {
                print "selection = null\n"
                return false
        }
        oleGet(objSelection, "Find", objFind)
        if (objFind == null) {
                print "find = null\n"
                return false
        }
 
        olePut(objFind, "Text", arg)
        olePut(objFind, "Wrap", wdFindContinue)
        oleMethod(objFind, cMethodExecute, null, bResult)
        if (bResult == false)
            print "The tag " arg " has not been found\n" 
    return bResult 
}


Alain

Thank you very much for your help. I ended up outputting the information to the top of the word document and then writing a find and replace word macro to properly position the text and clean up the document.